﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Flame.Dlr;

namespace Flame.Reflection
{
    
    public class RubyIntellisense : AIntellisense
    {
        IntellisenseParsing _regex, _regexM;
        public RubyIntellisense(IExecutable rubycompiler) : base(rubycompiler)
        {
            _regex = IntellisenseParsing.RegexBuilder(@"", @"((\:\:)|\.)", @"[a-zA-Z0-9_]");
            _regexM = IntellisenseParsing.RegexBuilder(@"", @"((\:\:)|\.)", @"[a-zA-Z0-9_]", @"\([^\)]*");
        }

        protected override IntellisenseParsing IntellisenseParsing_Method { get { return _regexM; } }
        protected override IntellisenseParsing IntellisenseParsing_Type { get { return _regex; } }


        protected override Type InstanceTypeFromName(string word)
        {
            return (Type)(_compiler.Execute("eval( '(" + word + ").GetType')").Data);
            //return (Type)((IronRuby.Builtins.Proc)x["instanceTypeFromName"]).Call(null, s);
        }

        protected override Type ClassTypeFromName(string word)
        {
            return (Type)(_compiler.Execute("eval( '(" + word + ").to_clr_type')").Data);
        }

        protected override string[] ClassTypeFromName_More(string word)
        {
            return (string[])(_compiler.Execute("eval( '(" + word + ").methods - Object.instance_methods')").Data);
        }


        protected override string[] Split(string word)
        {
            return word.Split(':', '.');
        }

        protected override string Clean(string word)
        {
            return word.TrimEnd('.', ':');
        }
    }
}
